﻿using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.Services.StartServices;
using IntelligentAgriculture.WebAPI.Application.Command.GermlineHistoryRecordsCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.GermlineHistoryRecordsCommandHandler
{
    /// <summary>
    /// 种母历史记录修改
    /// </summary>
    public class UpdateHistoryCommandHander : IRequestHandler<UpdateHistoryCommand, Results<int>>
    {

        private readonly IHistoryRecordService _service;

        public UpdateHistoryCommandHander(IHistoryRecordService service)
        {
            _service = service;
        }
        public async Task<Results<int>> Handle(UpdateHistoryCommand request, CancellationToken cancellationToken)
        {
            var entity = new Historyrecord()
            {
                BreedDate = request.BreedDate,
                BreedingRaw=request.BreedingRaw,
                CreateTime=request.CreateTime,
                CreateName="赵思彤",
                CurrentPregnancy=request.CurrentPregnancy,
                DeliveryDate=request.DeliveryDate,
                FreaksNumber=request.FreaksNumber,
                HealthyNumber=request.HealthyNumber,
                EarTag=request.EarTag,
                HealthyTotalWeight=request.HealthyTotalWeight,
                 MalformationNumber=request.MalformationNumber,
                 Hrid = request.Hrid,
                 LambNumber=request.LambNumber,
                 MummyNumber=request.MummyNumber,
                 PregnancyDate = request.PregnancyDate,
                 PregnancyResult=request.PregnancyResult,
                 StillbirthNumber=request.StillbirthNumber,
                 UpdateName="牛骞若",
                 UpdateTime=DateTime.Now,
                 WeaningCount   =request.WeaningCount,
                 WeaningDate=request.WeaningDate,
                 WeaningWeight = request.WeaningWeight,
                 Isdel=false
            };
            var list = await _service.UpdateAsync(entity);
            // 返回结果
            return Results<int>.DataResult(list);
        }
    }
}
